package ch04
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.text.TextField;

	/**
	 *创建多条曲线,错误做法
	 * @author jianping.shenjp
	 *
	 */
	public class MultiCurves1 extends Sprite
	{
		private var numPoints:uint=9;

		public function MultiCurves1()
		{
			init();
		}

		private function init():void
		{

			// first set up an array of random points 
			var points:Array=new Array();
			for (var i:int=0; i < numPoints; i++)
			{
				points[i]=new Object();
				points[i].x=Math.random() * stage.stageHeight;
				points[i].y=Math.random() * stage.stageHeight;
			}
			graphics.lineStyle(1);
			// now move to the first point 
			drawCircle(points[0], 0);
			graphics.moveTo(points[0].x, points[0].y);
			// and loop through each next successive pair 
			for (i=1; i < numPoints; i+=2)
			{
				drawCircle(points[i + 1], i + 1);
				graphics.curveTo(points[i].x, points[i].y, points[i + 1].x, points[i + 1].y);
			}
		}

		private function drawCircle(obj:Object, num:int):void
		{
			var sp:Sprite=new Sprite();
			var g:Graphics=sp.graphics;
			g.beginFill(0xFF0000);
			g.drawCircle(0, 0, 3);
			sp.x=obj.x;
			sp.y=obj.y;
			g.endFill();
			trace(sp.width);
			this.addChild(sp);
			var txt:TextField=new TextField();
			txt.text=num + "";
			txt.x=sp.x + 3;
			txt.y=sp.y;
			this.addChild(txt);
		}

	}
}